﻿@using System.Collections
@using GlobalResources
@using Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Helpers
@model Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Models.UnregisteredDeviceModel

@using (Ajax.BeginForm("AddDeviceCreate", "Device",
    new AjaxOptions()
    {
        UpdateTargetId = "content",
        HttpMethod = "POST",
        InsertionMode = InsertionMode.Replace,
        LoadingElementId = "loadingElement",
        OnFailure = "IoTApp.AddDeviceCreate.onFailure"
    }))
{
    @Html.AntiForgeryToken()
    <h3>@Strings.DeviceIdCreationPrompt</h3>

    <div class="deviceid_case_warning">@Strings.DeviceIdCaseSensitiveWarning</div>

    <fieldset class="add_device_create_form">

        <div class="radio_button">
            @Html.RadioButtonFor(m => m.IsDeviceIdSystemGenerated, "true", new { id = "deviceGeneratedBySystemYes" })
            @Html.LabelFor(m => m.IsDeviceIdSystemGenerated, @Strings.GenerateADeviceId, new { @for = "deviceGeneratedBySystemYes", @class = "radio_button__label" })
        </div>
        <div class="radio_button">
            @Html.RadioButtonFor(m => m.IsDeviceIdSystemGenerated, "false", new { id = "deviceGeneratedBySystemNo" })
            @Html.LabelFor(m => m.IsDeviceIdSystemGenerated, @Strings.LetMeDefineMyOwnDeviceId, new { @for = "deviceGeneratedBySystemNo", @class = "radio_button__label" })
        </div>
        <div class="unique_device_id" id="deviceIdInput">
            @Html.TextBoxFor(model => model.DeviceId,
                new
                {
                    @class = "unique_device_id__input",
                    id = "deviceId",
                    @Value = @Model.DeviceId ?? "",
                    @placeholder = @Strings.EnterDeviceId
                })

            <button class="button_base unique_device_id__check_id" id="checkIdButton" name="button" value="check" type="submit">@Strings.CheckId</button>

            @if (Model.IsDeviceIdUnique)
            {
                <div class="unique_device_id__error_check_id unique_device_id__error_check_id--available" id="deviceIdAvailable">
                    @Strings.DeviceIdAvailable
                </div>
            }

            @Html.DisplayFor(m => ViewData.ModelState)
        </div>
        <div class="add_iccid">
            <div>

                @Html.CheckBox("iccidFlagCheckbox")
                @Html.Label("iccidCheckBoxLabel", @Strings.AttachIccidToDevice, new { @for = "iccidFlagCheckbox" })

            </div>
            <div class="api_registration_not_available" id="noRegistration">
                @Strings.ApiRegistrationNotAvailable
            </div>
            <div>
                @if (ViewBag.CanHaveIccid)
                {
                    @Html.DropDownList("availableIccidList",
                        new SelectList((IEnumerable)ViewBag.AvailableIccids, null, null), new
                        {
                            id = "availableIccidList",
                            @class = "add_device_dropdown"
                        })
                }
            </div>
        </div>

    </fieldset>
    <fieldset class="fieldset_button">
        @Html.HiddenFor(m => m.DeviceType.Name)
        @Html.HiddenFor(m => m.DeviceType.DeviceTypeId)
        @Html.HiddenFor(m => m.DeviceType.Description)
        @Html.HiddenFor(m => m.DeviceType.InstructionsUrl)
        @Html.HiddenFor(m => m.DeviceType.IsSimulatedDevice)
        @Html.HiddenFor(m => m.Iccid, new { id = "hiddenIccidSelection" })
        @Html.Hidden("availableList")

        <button class="button_base" id="nextButton" type="submit">@Strings.Create</button>
        <button class="button_base button_secondary" type="button" onclick="location.href = '@Url.Action("Index", "Device")' ">@Strings.Cancel</button>
    </fieldset>
}

<script type="text/javascript">
    var resources = {
        addDevice: '@Html.JavaScriptString(string.Format(Strings.AddADeviceFormatted, Model.DeviceType.Name))',
        redirectToIndexUrl: '@Url.Action("AddDevice", "Device")',
        stepTwoHeader: '@Html.JavaScriptString(Strings.StepTwoHeader)',
        enterDeviceId: '@Html.JavaScriptString(Strings.EnterDeviceId)',
        createDeviceError: '@Html.JavaScriptString(Strings.DeviceAddError)',
        canHaveIccid: '@ViewBag.CanHaveIccid'
    }

</script>

<script type="text/javascript" src="~/Scripts/Views/Device/AddDeviceCreate.js?ver=@Constants.JSVersion"></script>
